<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/commonPage/common.jsp"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<link rel="stylesheet" href="${base }/style/newPolicy.css">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>最新政策</title>
</head>
<style>
	.newPolicy-items{
		overflow: hidden;
	}
</style>
<body class="inner-container" style="padding-top: 6%; " >
	<div class="newPolicy-content" style="padding-bottom: 20px; cursor: pointer;">
		<div class="newPolicy-items" id="newPolicy-list"></div>
	</div>
	<div style="width: 100%; text-align: right; position: fixed; bottom: 10px;">
		<div id="page-newPolicy" style="width: 60%;margin: 0 auto;"></div>
	</div>
</body>
<script type="text/javascript">
	var data = '';
	var total =  ${requestScope.total};

	layui.use(['laypage'], function() {
		var laypage = layui.laypage;
		$("#page-newPolicy").each(function(i,the){
			laypage.render({
				elem: the //注意，这里的 test1 是 ID，不用加 # 号
				,count: total //数据总数，从服务端得到
				, limit: 5                     //每页显示条数
				, limits: [4, 10, 20]
				,curr: location.hash.replace('#!page=', '') //获取起始页
			  	,hash: 'page' //自定义hash值
				, groups: 5                      //连续页码个数
				, prev: '上一页'                 //上一页文本
				, netx: '下一页'                 //下一页文本
				, first: 1                      //首页文本
				, last: 100                     //尾页文本
				, layout: ['prev', 'page', 'next','refresh','skip']
				//跳转页码时调用
				, jump: function (obj, first) { //obj为当前页的属性和方法，第一次加载first为true
						//清空以前加载的数据
						$('#newPolicy-list').empty();
						//调用加载函数加载数据
						showReocrd(obj.curr,obj.limit);
				}
			});
		})
	})

	// 加载数据
	function showReocrd(page,limits){
		$.get("${base}/policy/getPolicyAction",
				{
					page:page,
					limits:limits
				},
				function (res) {
					if (res.code===0) {
						data=res.data;
						var arr = new Array();
						layui.each(data, function(index, item) {
							arr.push('<div class="newPolicy-item" onclick="getNewPolicyData(this)">' + '<p id="newPolicy-id" class="layui-hide">' + item.id + '</p>'
									+ '<div class="newPolicy-img img-transform"><img src="'+item.imgUrl+'"></div>' + '<div class="newPolicy-content">' + '<div class="newPolicy-title"><h2>'
									+ item.title + '</h2></div>' + '<div class="newPolicy-time"><h3>' + item.time.substr(0, 4) + '年' + item.time.substr(5, 2) + '月'
									+ item.time.substr(8, 2) + '</h3></div>' + '<div class="newPolicy-context"><p>' + delHtmlTag(item.context) + '</p></div>' + '</div>' + '</div>')
						});
						$(".newPolicy-items").html(arr);
					} else {
						layer.msg("数据加载异常！");
					}
				},
				"json"
		);
	}


	function getNewPolicyData(ele) { //获取点击最新新闻所对应的数据并跳转到指定页面展示
		var thisData = data.find(function(item) { //获取点击最新新闻所对应的数据
			return item.id == $($(ele).find("#newPolicy-id")[0]).html();
		});
		window.location.href = 'newPolicyDetail?id=' + thisData.id; //带上点击信息的id跳转到新页面
	}
</script>
</html>